import apis from '../../http/apis/apis.js'
import lessors from "../../http/apis/modules/lessors.js"

export default {
    //避免命名冲突
    namespaced: true,
    state: {
        lessorsData: [],
        pageSize: 5,
        currentPage: 1,
        nums: 1,
        type: 'account',
        value: ''
    },

    mutations: {
        changeLessorsData(state, data) {
            state.lessorsData = data
        },
        //修改数据总条数
        changeNums(state, data) {
            state.nums = data
        },
        //修改每页显示条数
        changePageSize(state, pageSize) {
            state.pageSize = pageSize
        },
        //修改当前页
        changeCurrentPage(state, currentPage) {
            state.currentPage = currentPage
        },
        // 修改type
        changeType(state, type) {
            state.type = type
        },
        // 修改value
        changeValue(state, value) {
            state.value = value
        }
    },
    actions: {
        // 获取出租方数据
        async getLessors(context) {
            const { data } = await apis.lessors.getLessors({
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
                type: context.state.type,
                value: context.state.value,
            });
            context.commit("changeLessorsData", data.data.data)
            context.commit("changeNums", data.data.nums)
        },
        // 冻结账户
        async frozenAccount(context, _id) {
            const { data } = await apis.lessors.frozenAccount(_id);
            if (data.status == 1) {
                alert("操作成功！");
            }
        },
        // 冻结账户
        async thawAccount(context, _id) {
            const { data } = await apis.lessors.thawAccount(_id);
            if (data.status == 1) {
                alert("操作成功！");
            }

        }
    }
}